package com.yunyi.camunda.controller;


import com.yunyi.camunda.common.utils.UserUtils;
import com.yunyi.camunda.pojo.Result;
import com.yunyi.camunda.pojo.dto.User;
import com.yunyi.camunda.pojo.vo.DeployRequestParam;
import com.yunyi.camunda.service.ProcessDefinitionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 流程部署controller
 *
 * @author yunyi
 */
@RequestMapping("/process/definition")
@RestController
public class ProcessDefinitionController {

    @Autowired
    private ProcessDefinitionService processDefinitionService;

    /**
     * 发布流程定义
     *
     * @param requestParam 请求参数
     * @return 提示信息
     */
    @PostMapping("/deploy")
    public Result<String> deployProcessDefinition(@RequestBody DeployRequestParam requestParam) {
        User virtualUser = UserUtils.getVirtualUser();
        return processDefinitionService.deploy(virtualUser, requestParam);
    }

    /**
     * 删除部署
     *
     * @param deploymentId 部署id
     * @return 提示信息
     */
    @GetMapping("/deleteDeployment")
    public Result<String> deleteDeployment(@RequestParam("deploymentId") String deploymentId) {
        return processDefinitionService.deleteDeployment(deploymentId);
    }


}
